/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/authorizationService.ts" />
/// <reference path="../src/tms.ts" />

describe("getAuthorizationList",()=>{
    var injector:ng.auto.IInjectorService;
    var service:IAuthorizationService;

    beforeEach(()=>{
        injector=angular.injector(['ng','tms']);
        service=injector.get<IAuthorizationService>('authorizationService');
    });

    //常规无条件获取
    it('get authorization list normal',(done)=>{
       service.getList(null,null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||0|10');
           done();
       },(err)=>{
           done.fail(err);
       });
    });

    //获取权限tag包含 Get 的权限列表
    it('get authorization list by tag \'Get\'',(done) => {
        service.getList('Get',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('Get||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取权限分类编号包含 财务 的权限列表
    it('get authorization list by categoryId \'财务\'',(done) => {
        service.getList(null,'财务',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|财务|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 权限tag包含 Get,权限分类编号包含 财务 的权限列表
    it('get authorization list by  tag \'Get\' and categoryId \'财务\'',(done) => {
        service.getList('Get','财务',0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('Get|财务|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取权限详情
    it('get detail',(done) => {
        service.getDetail('3').then((res) => {
            expect(res.data.tag).toBe("Get");
            expect(res.data.controller).toBe("Fee");
            expect(res.data.action).toBe("GetDetail");
            expect(res.data.categoryId).toBe("财务");
            expect(res.data.isEnabled).toBe(true);
            expect(res.data.description).toBe("说明");
            expect(res.data.extData).toBe("3");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //添加权限
    it('add authorization ',(done)=>{
        service.add('测试','测试/TMS','测试','报表',true,'说明').then((res)=>{
            expect(res.data.extData).toBe("测试|测试/TMS|测试|报表|true|说明");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑权限
    it('edit authorization ',(done)=>{
        service.edit('1','测试2','测试2/TMS','测试2','报表',false,'说明2').then((res)=>{
            expect(res.data.extData).toBe("1|测试2|测试2/TMS|测试2|报表|false|说明2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除权限
    it('delete authorization',(done)=>{
        service.delete('2').then((res)=>{
            expect(res.data.extData).toBe("2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //权限编号2 是否有权限
    it('get isauth by id \'2\' ',(done)=>{
        service.auth('2').then((res)=>{
            expect(res.data.extData).toBe("2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //权限编号2,禁用权限
    it('get enabled by id \'2\' and disabled false  ',(done)=>{
        service.disabled('2',false).then((res)=>{
            expect(res.data.extData).toBe("2|false");
            done();
        },(err)=>{
            done.fail(err);
        });
    });


});